<!--
 * @Author: panda
 * @Date: 2022-05-18 10:04
 * @Description: Markdown 展示组件，copy别人的
-->
<template>
  <div id="viewer" :class="$props.class" class="markdown-viewer"></div>
</template>

<script lang="ts" setup>

import { watch,} from 'vue'
import Vditor from 'vditor'
import 'vditor/dist/index.css'

const props = defineProps({
  value: {type: String},
  class: {type: String}
})

watch(()=>props.value,(cur) => {
  const viewer: HTMLDivElement = document.getElementById('viewer') as HTMLDivElement
  Vditor.preview(viewer,  cur|| '', {
    mode: "light",
    lang: "zh_CN",
    anchor: 1, // 0: no render, 1: render left, 2: render right
  })
})
</script>

<style scoped>
.markdown-viewer {
  width: 100%;
}
</style>
